<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	//显示统计数据
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$order['all']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3,5,6)));
	$order['day']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3,5,6),'createtime >'=>$daytime));
	$money['all']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1),'price');
	$money['day']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$daytime),'price');
	
	$order['table']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>1));
	$order['out']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>2));
	$order['self']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>3));
	$order['yuyue']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>4));
	
	$money['table']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>1));
	$money['out']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>2));
	$money['self']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>3));
	$money['yuyue']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>4));
		
	$member['day'] = pdo_count('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime));
	$member['all'] = pdo_count('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid']));
	$access['day'] = pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'jy_weishop','createtime >'=>$daytime));
	$access['all'] = pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'jy_weishop'));
	//月份
	for($i=0;$i<12;$i++){
			if($i==0){
				$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
				$yueend = time();
				
			}else{
				$yuestart = mktime(0,0,0,date('m')-$i,1,date('Y'));
				$yueend = mktime(0,0,0,date('m')-$i+1,1,date('Y'));
			}
			$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3,5,6));
			$params['createtime between']=array($yuestart,$yueend);
			$month12[] = date('Y-m',strtotime('-'.$i.' month'));
			//$monthaccess[]=pdo_count('core_access_log',$params);
			$monthorder[]=pdo_count('jy_weishop_order',$params);
			$monthfee=pdo_getsum('jy_weishop_order',$params,'price');
			$monthmoney[]=intval($monthfee);
			//$monthcredit2[]=pdo_getsum('core_members',$params,'credit2');
	}
	$monthorder=array_reverse($monthorder);
	$monthmoney=array_reverse($monthmoney);
	$month12=array_reverse($month12);
	$htmls=array(
		array('type'=>'data','num'=>12,'one_num'=>3,'title'=>'今日数据/总数据','datas'=>array(
			array('title'=>'总订单数(成功的)','num'=>2,'data'=>array($order['day'],$order['all'])),
			array('title'=>'订单金额(支付的)','yuan'=>1,'num'=>2,'data'=>array($money['day'],$money['all'])),
			array('title'=>'访客统计','num'=>2,'data'=>array($access['day'],$access['all'])),
			array('title'=>'总用户','num'=>2,'data'=>array($member['day'],$member['all'])),
		)),
		array('type'=>'echarts_arealine','ecid'=>'mobile','title'=>'月度成交金额','datas'=>array(
					'datas'=>array(
						array('name'=>'成交订单数','value'=>$monthorder),
						array('name'=>'成交订单金额','value'=>$monthmoney),
					),
					'xdatas'=>$month12,
		)),
	);
	$getlegaos = cache_read('plugin_getlegaos','jy_weishop');
	if(!$getlegaos){
			$getlegaos=cloud_request('release.get_plugins.legaos',array('basic'=>'jy_weishop'),'',true);
			cache_write('plugin_getlegaos',$getlegaos,'jy_weishop');
	}
	$getlegaos=json_decode($getlegaos,true);
	$return['item']['legaos']=$getlegaos['list'];
	$return['item']['legaosgroups']=$getlegaos['groups'];
	$gettpls = cache_read('plugin_gettpls','jy_weishop');
	if(!$gettpls){
			$gettpls=cloud_request('release.get_plugins.tpls',array('basic'=>'jy_weishop'),'',true);
			cache_write('plugin_gettpls',$gettpls,'jy_weishop');
	}
	$gettpls=json_decode($gettpls,true);
	$return['item']['tpls']=$gettpls['list'];
	$return['item']['tplsgroups']=$gettpls['groups'];
	if($_SESSION['isfounder'] && $_SESSION['os']=='windows'){
		$htmls[]=array('type'=>'legaos','title'=>'推荐场景体（仅超级管理员可见）','style'=>3,'pluginname'=>$plugin_name,'name'=>'legaos','groups'=>'legaosgroups');
		$htmls[]=array('type'=>'legaos','title'=>'推荐商城模板（仅超级管理员可见）','style'=>3,'pluginname'=>$plugin_name,'name'=>'tpls','groups'=>'tplsgroups');
	}
	$setting=$this->plugin_setting('setting');
	if($_SESSION['os']=='windows' && (empty($setting['share_title']) || empty($setting['hdps']))){
		$htmls[]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
			array('element'=>'#left_menu_0_1','intro'=>'主人！您还没有设置页面噢！</br>只有设置好了页面，才能有好的体验噢！点这里设置噢！','position'=>''),
		));
	}
	$iswechat=pdo_getcolumn('core_account_wechat',array('uniacid'=>$_SESSION['uniacid']),'id');
	$site=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('title','logo','desc','ewm','credit2','groupid'));
	if($_SESSION['os']=='windows' && (empty($setting['share_title']) || empty($setting['hdps']))){
		if(empty($site['title']) || empty($site['desc'])){
			$htmls[]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#gowelcome','intro'=>'主人您好！您还没有设置好站点信息噢！</br>只有设置好了信息，才能有好的体验！点这里开始噢！</br>点这里-》返回站点-》站点设置','position'=>'bottom-middle-aligned'),
			));
		}elseif(empty($iswechat)){
			$htmls[]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#gowelcome','intro'=>'主人您好！您还没有添加默认公众号噢！</br>添加了默认有效的公众号，才能实现扫码登录，粉丝同步，微信支付等体验！</br>点这里-》返回站点-》应用端-》公众号管理','position'=>'bottom-middle-aligned'),
			));
		}
	}
	//if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	/*}else{
		$avatar=pdo_getcolumn('core_members',array('id'=>$return['item']['mid']),'avatar');
		$return['plugin']= pdo_get('core_plugins',array('name'=>$_SESSION['plugin_name']));
		$return['account']=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('title','desc','logo','groupid','credit2','endtime','opendiys'));
		$return['group']=pdo_get('core_account_group',array('id'=>$account['groupid']),array('id','title','access','resource','opendiys'));
		$return['store']['logo']=$return['store']['logo']?$return['store']['logo']:$avatar;
		$return['status0']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>0,'createtime >'=>$daytime));
		$return['status1']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'createtime >'=>$daytime));
		$return['status2']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>2,'createtime >'=>$daytime));
		$return['status3']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'createtime >'=>$daytime));
		$return['status4']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>4,'createtime >'=>$daytime));
		$return['ispay']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$daytime),'id');
		$return['ispayfee']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$daytime),'price');
		$return['orderfee']=price($return['ispayfee']/$return['ispay']);
		$return['goodsnum']=pdo_count('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>0),'id');
		$return['verifygoodsnum']=pdo_count('jy_weishop_verifygoods_log',array('uniacid'=>$_SESSION['uniacid'],'salerid'=>$_SESSION['uid'],'verifydate >'=>$daytime),'id');
		$return['verifynum']=pdo_count('jy_weishop_order_verify',array('uniacid'=>$_SESSION['uniacid'],'clerk_id'=>$_SESSION['uid'],'verifytime >'=>$daytime),'id');
		$return['selfverifynum']=pdo_count('jy_weishop_order_self',array('uniacid'=>$_SESSION['uniacid'],'clerk_id'=>$_SESSION['uid'],'verifytime >'=>$daytime),'id');
		$verifylog=pdo_getall('jy_weishop_order_verify',array('uniacid'=>$_SESSION['uniacid'],'clerk_id'=>$_SESSION['uid'],'verifytime >'=>$daytime),array('orderid'));
		$return['verifyfee']=0;
		foreach($verifylog as &$vo){
			$vo['price']=pdo_getcolumn('jy_weishop_order',array('id'=>$vo['orderid']),'price');
			$return['verifyfee'] +=$vo['price'];
		}
		$selfverifylog=pdo_getall('jy_weishop_order_self',array('uniacid'=>$_SESSION['uniacid'],'clerk_id'=>$_SESSION['uid'],'verifytime >'=>$daytime),array('orderid'));
		$return['selfverifyfee']=0;
		foreach($selfverifylog as &$so){
			$so['price']=pdo_getcolumn('jy_weishop_order_self',array('id'=>$so['orderid']),'price');
			$return['selfverifyfee'] +=$so['price'];
		}
		$return['top_plugin_menu']=$this->menu();
	}*/
	exi($return);
}